package com.labofjet.blogv3.service.impl;

import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;

import com.labofjet.blogv3.dao.IHistoryDao;
import com.labofjet.blogv3.model.History;

@Service
public class HistoryService {
	@Autowired
	private IHistoryDao dao;

	@Cacheable(value = "history", key = "'all'")
	public List<History> findAllHistory() {
		List<History> list = dao.findAll();
		Collections.reverse(list);
		return list;
	}

	@Caching(evict = { @CacheEvict(value = "history", allEntries = true) })
	public void save(History h) {
		dao.save(h);
	}
}
